import { useUserStore } from "@/store/user";
import router from "@/router";

export function logout(before?: () => void, after?: () => void) {
  const userStore = useUserStore();
  before && before();
  localStorage.removeItem("token"); //删token
  // 清空动态路由
  userStore.routes.forEach((del) => {
    router.removeRoute(del.name);
    console.log(del.name);
  });
  // 清空全局数据
  userStore.username = "";
  userStore.menus = [];
  router.push("/login"); //跳转回登录页
  after && after(); //如果没有参数就不调用
}